package com.nwpu.service.impl;



import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.nwpu.domain.Goods;
import com.nwpu.domain.Order;
import com.nwpu.mapper.OrderMapper;
import com.nwpu.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
* @author DPH
* @description 针对表【tbl_order】的数据库操作Service实现
* @createDate 2023-06-08 13:07:01
*/
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order>
    implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public boolean saveOrder(Order order) {
        return orderMapper.insert(order) > 0;
    }

    @Override
    @Async("taskExecutor")
    @Retryable(value = RetryException.class, maxAttempts = 5, backoff = @Backoff(delay = 2000L, multiplier = 1.5))
    public boolean saveOrder2(Order order) throws RetryException {
        int res = orderMapper.insert(order);
        // 继续 重试
        if(res == 0){
            throw new RetryException("待同步 订单号："+order.getOrderId());
        } else {
            return true;
        }
    }

    @Recover
    public boolean recover(RetryException e){
        return false;
    }
}




